Repository navigation
feat(oauth): log rate-limit rejections on the OAuth endpoints as security events - #1174
Merged
Merged
Conversation
…rity events The global OnRejected callback emitted Auth.RateLimitRejected only for the login and refresh policies. It now emits for every attached policy except client-errors, which adds oauth-authorize, oauth-token, oauth-register and oauth-api, and the event carries the policy name. Refs #1164
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The global rate-limit rejection callback logged
Auth.RateLimitRejectedonly for the login and refresh policies. A 429 fromoauth-authorize,oauth-token,oauth-registeroroauth-apiproduced no security event.Closes #1164
What changed
CluckworkRateLimitingServiceCollectionExtensionsstill reads the policy attached to the endpoint. It now logs the event for every policy exceptclient-errors, so the four OAuth policies are covered. A policy added later also logs unless someone excludes it. The event gains aPolicyproperty:The 429 body,
Retry-After, the limits and the partition keys did not change.PathisRequest.Path, which never includes the query string. The event logs the client IP, not theoauth-apipartition key, because that key is a hash of the bearer token.I chose an exclusion over an allow-list of six names. Both earlier misses had the same cause: a list that did not name the new endpoints. Only
client-errorsis meant to stay silent, so it is the only name the code checks.The comments in
SecurityEventsandDistributedFixedWindowPolicy, and the event table indocs/security/log-redaction-policy.md, now list the six policies and thePolicyfield.Tests
AuthRateLimitLoggingTestsgains one theory with four cases, one per OAuth policy. The factory sets each OAuth limit to 1.oauth-apiuses a test-onlyAcceptOAuthTokensendpoint, because no production endpoint accepts OAuth tokens yet. Each case checks that:Retry-Afterand logs exactly one warning with the expectedPolicy,ClientIpandPath;The existing
client-errorscontrol still asserts no event. The login and step-up tests still pass.Local runs at
9aca684c, with Testcontainers Postgres:AuthRateLimitLoggingTests,DistributedRateLimiterWiringTests,OAuthFailClosedTestsandOAuthClientRegistrationTests: 120 passed, 0 failed.ImagePintracked-file guards: 2 passed.No test or guard registry lists security events or policy names. A grep of
tests/forSecurityEventsand the policy-name constants found only the two rate-limit test files above.Mutation check
I ran each mutation against the callback at
9aca684c, then ranAuthRateLimitLoggingTests(7 tests) and restored the file.oauth-apias well asclient-errorsoauth-apionlyclient-errorsexclusionRequest.QueryStringtoPathoauth-authorizeonly (its secret travels in the query string)